package com.qiyadeng.wechat.roo.model;

import java.util.List;

import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

import com.qiyadeng.wechat.config.WeChatConstant;

@RooJavaBean
@RooToString
@RooJpaActiveRecord(versionField = "", table = "PRO_WECHAT")
@RooDbManaged(automaticallyDelete = true)
public class ProWechat {

	
	public static List<ProWechat> findAllProWechats() {
        return entityManager().createQuery("SELECT o FROM ProWechat o", ProWechat.class).getResultList();
    }
	
	//根据描述和名称查询
	public static List<ProWechat> findProWechatsByNameAndDesc(String key) {
        return entityManager().createQuery("SELECT o FROM ProWechat o where o.proName like ?1 or o.proDes like ?2", ProWechat.class)
        		.setParameter(1, "%"+key+"%")
        		.setParameter(2, "%"+key+"%")
        		.getResultList();
    }
	
	//保存最新活动信息
	public static void savePromotion(){
		//String type = "PROMOTION";
	}
	
	//取得最新活动信息
	public static List<ProWechat> getLastestPromotion(){
		String type = "PROMOTION";
		List<ProWechat> proList = entityManager().createQuery("select o from ProWechat o where o.type=?1 order by o.addTime desc", ProWechat.class)
		.setParameter(1, type)
		.setMaxResults(WeChatConstant.LASTEST_PROMOTION_SIZE)
		.getResultList();
		return proList;
	}
}
